package com.jay.android.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class SpeedView extends ImageView {
	private float mSpeed;
	private Drawable indicator;

	public SpeedView(Context context) {
		super(context);
		mSpeed = 0;
		indicator = null;
	}

	public SpeedView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mSpeed = 0;
		indicator = null;
	}

	public SpeedView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mSpeed = 0;
		indicator = null;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		if (indicator == null) {
			indicator = getDrawable();
			indicator.setBounds(0, 0, getWidth(), getHeight());
		}

		canvas.save();
		canvas.rotate((mSpeed - 120), getWidth() / 2, getHeight() / 2);
		indicator.draw(canvas);
		canvas.restore();
	}

	public void updateSpeed(float speed) {
		mSpeed = speed;
		invalidate();
	}

	public float getSpeed() {
		return mSpeed;
	}
}
